Visualizing `<`, `>`, `<=`, `>=`, `instanceof`, and `in`.
These operators compare two operands and return a boolean value (`true` or `false`). They perform type coercion, which can lead to unexpected results when comparing different types.
5 > 3; // true 10 <= 10; // true "2" > 1; // true (string "2" is coerced to number 2)
Expression: `10 > 5`
Result:
Expression: `10 <= 5`
Result:
Expression: `10 <= 10`
Result:
Expression: `"10" > 5`
Result:
Expression: `10 < "5"`
Result:
Expression: `"a" > "b"`
Result:
**`instanceof`** checks if an object is an instance of a particular class or constructor function. **`in`** checks if a property exists in a specified object or its prototype chain.
const d = new Date(); d instanceof Date; // true d instanceof Object; // true const user = { name: "Alice" }; "name" in user; // true "age" in user; // false
Object: const d = new Date()
Expression: `d instanceof Date`
Result:
Expression: `d instanceof Object`
Result:
Expression: `d instanceof Array`
Result:
Object: const person = { name: 'Bob' }
Expression: `"name" in person`
Result:
Expression: `"toString" in person`
Result:
Expression: `"age" in person`
Result: